<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="com.cgt.web.util.PageInfo" %>
<%@ page import="com.cgt.web.pojo.Classroom" %><%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2025/2/7
  Time: 19:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>class</title>
    <link rel="stylesheet" href="static/bootstrap-3.4.1-dist/css/bootstrap.css">
</head>
<body>
    <%
      PageInfo<Classroom> pageInfo = (PageInfo<Classroom>) request.getAttribute("pageInfo");
    %>
    <a class="btn btn-primary" href="class_add.jsp">添加数据</a>
    <table class="table table-striped table-bordered table-hover table-condensed">
      <tr>
        <td>ID</td>
        <td>名称</td>
        <td>位置</td>
        <td>座位数量</td>
      </tr>
      <c:forEach items="${pageInfo.list}" var="classroom">
        <tr>
            <td>${classroom.id}</td>
            <td>${classroom.name}</td>
            <td>${classroom.address}</td>
            <td>${classroom.seatsum}</td>
            <td><a href="/classroom?method=toUpdate&id=${banji.id}">修改</a></td>
            <td><a href="javascript:void(0)" onclick="deleteById(${banji.id})">删除</a></td>
        </tr>
      </c:forEach>
    </table>
<%--        <%--%>
<%--          for (Classroom classroom : pageInfo.getList()) {--%>
<%--        %>--%>
<%--        <tr>--%>
<%--            <td><%=classroom.getId()%></td>--%>
<%--            <td><%=classroom.getName()%></td>--%>
<%--            <td><%=classroom.getAddress()%></td>--%>
<%--            <td><%=classroom.getSeatsum()%></td>--%>
<%--            <td><a href="/classroom?method=selectById&id=<%=classroom.getId()%>">修改</a></td>--%>
<%--            <td><a href="javascript:void(0)" onclick="deleteById(<%=classroom.getId()%>)">删除</a></td>--%>
<%--        </tr>--%>
<%--        <%--%>
<%--          }--%>
<%--        %>--%>

    <nav aria-label="Page navigation">
        <ul class="pagination">
            <c:if test="${pageInfo.pageNo==1}">
                <li class="disabled">
                    <a href="#" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
            </c:if>
            <c:if test="${pageInfo.pageNo!=1}">
                <li>
                    <a href="/classroom?method=selectByPage&pageNo=${pageInfo.pageNo-1}" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
            </c:if>
            <c:forEach begin="1" end="${pageInfo.totalPage}" step="1" var="i">
                <c:if test="${i==pageInfo.pageNo}">
                    <li class="active"><a href="#">${i}</a></li>
                </c:if>
                <c:if test="${i!=pageInfo.pageNo}">
                    <li><a href="/classroom?method=selectByPage&pageNo=${i}&pageSize=5">${i}</a></li>
                </c:if>
            </c:forEach>

            <c:if test="${pageInfo.pageNo==pageInfo.totalPage}">
                <li class="disabled">
                    <a href="#" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            </c:if>
            <c:if test="${pageInfo.pageNo!=pageInfo.totalPage}">
                <li>
                    <a href="/classroom?method=selectByPage&pageNo=${pageInfo.pageNo+1}" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            </c:if>
        </ul>
    </nav>
    <script>
        function deleteById(id){
            var isDelete = confirm('真的要删除这条记录吗？');
            if(isDelete){
                location.href = "/classroom?method=deleteById&id=" + id;
            }
        }
    </script>

</body>
</html>
